package com.tbit.main.service.impl;

import com.tbit.main.constant.DaoParamConstant;
import com.tbit.main.dao.core.AdoptMachineBoundDao;
import com.tbit.main.pojo.AdoptMachineBound;
import com.tbit.main.pojo.OrderDateSta;
import com.tbit.main.pojo.RideSta;
import com.tbit.main.service.AdoptMachineBoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 代理商配置
 *
 * @author Leon
 * 2019年11月19日 上午10:49:57
 */
@Service("adoptMachineBoundService")
public class AdoptMachineBoundServiceImpl implements AdoptMachineBoundService {
    @Autowired
    private AdoptMachineBoundDao adoptMachineBoundDao;

    @Override
    public List<AdoptMachineBound> getByAccountUserId(Integer accountUserId) {
        return adoptMachineBoundDao.getByAccountUserId(accountUserId);
    }

    @Override
    public RideSta staByDate(Integer accountUserId, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        List<Integer> machineIds=adoptMachineBoundDao.selectByMachineId(accountUserId);
        if(!machineIds.isEmpty()) {
            params.put("machineIds", machineIds);
            params.put("accountUserId", accountUserId);
            params.put(DaoParamConstant.startTime, startTime);
            params.put(DaoParamConstant.endTime, endTime);
            return adoptMachineBoundDao.staByDate(params);
        }else {
            // 领养人车辆为空，返回空
            return new RideSta();
        }
    }

    @Override
    public List<OrderDateSta> orderStaGroupByDate(Integer accountUserId, String startTime, String endTime) {
        Map<String, Object> params = new HashMap<String, Object>();
        List<Integer> machineIds=adoptMachineBoundDao.selectByMachineId(accountUserId);
        if(!machineIds.isEmpty()){
            params.put("machineIds", machineIds);
            params.put("accountUserId", accountUserId);
            params.put(DaoParamConstant.startTime, startTime);
            params.put(DaoParamConstant.endTime, endTime);
            return adoptMachineBoundDao.orderStaGroupByDate(params);
        } else {
            // 领养人车辆为空，返回空
            return new ArrayList<>();
        }
    }

}
